package genericity_try;

import java.lang.reflect.Array;

public class GenericArray<T> {

    private final T[] array;

    public GenericArray(Class<T> type, int size) {
        array = (T[]) Array.newInstance(type, size);
    }

    public void put(int index, T item) {
        array[index] = item;
    }

    public T get(int index) {
        return array[index];
    }

    public T[] create() {
        return array;
    }

    public static void main(String[] args) {
        GenericArray<Integer> arrayToken = new GenericArray<>(Integer.class, 100);
        Integer[] array = arrayToken.create();
        System.out.println(array.length);
    }
}
